<?php
namespace api\xcx\controller;
use think\Cache;
use think\Loader;
use think\Db;
use think\Request;
use think\Controller;
use think\config;
/**
 *  Water.php Water控制器
 *
 * @copyright			(C) 2014-2018 ShengTeng
 * @lastmodify			2018-05-21
 */
class Water extends Base
{
    /**
     * @api {POST} Water/staffrankingToday 员工今日排名
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} token 员工token
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data" 返回的数据就是名次
     *      }
     */
    public function staffrankingToday(Request $request){
        $params = $request->param();
        $token = $this->checkParam($params['token'],'token',true);
        $staff = $this->selStaff($token);
        $water = Model('Water');
        $res = $water->staffrankingToday($staff['userId']);
        if($res || $res==0){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }

    /**
     * @api {POST} Water/ranking 今日排行榜
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {Int} page 页数
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *              "moneys" 收入金额
     *               "serverNum" 服务人数
     *               "userName" 员工名称
     *               "num" 排名
     *          }
     *      }
     */
   public function ranking(Request $request){
        $params = $request->param();
        $page = $this->checkParam($params['page'],'page',true);
        if($page<=0){
            return json(returnAjax(null,'page格式错误',1));
        }
       $water = Model('Water');
        $res = $water->todayRanking($page);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
   }


   /**
     * @api {POST} Water/staffIncome 员工收入
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} token 员工token
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                  "month": 本月收入
    *                   "today" 今日收入
     *          }
     *      }
     */
    public function staffIncome(Request $request){
        $params = $request->param();
        $token = $this->checkParam($params['token'],'token',true);
        $staff = $this->selStaff($token);
        $water = Model('Water');
        $res = $water->StaffmonthInfo($staff['userId']);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }


    /**
     * @api {POST} Water/staffTodayComIncome 员工今日每个项目收入
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} token 员工token
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                      "id" 项目id
     *                       "name" 名称
     *                       "money" 收入
     *          }
     *      }
     */
    public function staffTodayComIncome(Request $request){
        $params = $request->param();
        $token = $this->checkParam($params['token'],'token',true);
        $staff = $this->selStaff($token);
        $water = Model('Water');
        $res = $water->staffProTodayInfo($staff['userId']);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }


    /**
     * @api {POST} Water/shopThisMonthIn 店铺本月收入信息
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} shopId 店铺id
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                  "month" 本月收入
     *                   "today" 本日收入
     *                   "wx" 本日微信收入
     *                   "xj" 本日现金收入
     *          }
     *      }
     */
    public function shopThisMonthIn(Request $request){
        $params = $request->param();
        $shopId = $this->checkParam($params['shopId'],'shopId',true);
        $isShop = $this->selShop($shopId);
        $water = Model('Water');
        $res = $water->shopIncomeMonth($shopId);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }


     /**
     * @api {POST} Water/shopThisMonthComIn 店铺某月项目收入信息
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} shopId 店铺id
     * @apiParam {String} year 年,4位
     * @apiParam {String} month  月 2位
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                      "id" 项目id
     *                       "name" 名称
     *                       "money" 收入
     *          }
     *      }
     */
    public function shopThisMonthComIn(Request $request){
        $params = $request->param();
        $shopId = $this->checkParam($params['shopId'],'shopId',true);
        $year = $this->checkParam($params['year'],'year',true);
        $month = $this->checkParam($params['month'],'month',true);
        $isShop = $this->selShop($shopId);
        $water = Model('Water');
        $res = $water->shopIncomeComMonth($shopId,$year,$month);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }

    /**
     * @api {POST} Water/shopMonthIn 店铺某月收入信息
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} shopId 店铺id
     * @apiParam {String} year 年,4位
     * @apiParam {String} month  月 2位
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                  "month" 某月月收入
     *                   "wx" 某月微信收入
     *                   "xj" 某月现金收入
     *          }
     *      }
     */
    public function shopMonthIn(Request $request){
        $params = $request->param();
        $shopId = $this->checkParam($params['shopId'],'shopId',true);
        $year = $this->checkParam($params['year'],'year',true);
        $month = $this->checkParam($params['month'],'month',true);
        $isShop = $this->selShop($shopId);
       
        $water = Model('Water');
        $res = $water->shopMonthIncome($shopId,$year,$month);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }

     /**
     * @api {POST} Water/todayStaffInList 店铺当日员工收入
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} shopId 店铺id
     * @apiParam {String} page 页数
     * @apiParam {String} month  月 2位
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                  "name" 名称
     *                   "money" 收入
     *          }
     *      }
     */
        public function todayStaffInList(Request $request){
            $params = $request->param();
            $shopId = $this->checkParam($params['shopId'],'shopId',true);
            $page = $this->checkParam($params['page'],'page',true);
            $isShop = $this->selShop($shopId);
            if($page<1){
                return json(returnAjax('','page有误','1'));
            }
            $water = Model('Water');
            $res = $water->todayStaffInList($page,$shopId);
            if($res || $res == []){
                return json(returnAjax($res));
            }else {
                return json(returnAjax('','系统有误','-1'));
            }
        }
    
    /**
     * @api {POST} Water/monthshopInday 店铺某月每日收入列表
     * @apiVersion 1.0.1
     * @apiGroup 流水
     *
     * @apiParam {String} shopId 店铺id
     * @apiParam {String} year 年,4位
     * @apiParam {String} month  月 2位
     * 
     * @apiSuccess {Int} code 返回码
     * @apiSuccess {String} message  提示信息
     * @apiSuccess {Object} data  返回数据
     *
     * @apiSuccessExample {json} Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *          "code":0,
     *          "message":"",
     *          "data":{
     *                  "d" 日期
     *                   "money" 金额
     *          }
     *      }
     */
    public function monthshopInday(Request $request){
        $params = $request->param();
        $shopId = $this->checkParam($params['shopId'],'shopId',true);
        $year = $this->checkParam($params['year'],'year',true);
        $month = $this->checkParam($params['month'],'month',true);
        $isShop = $this->selShop($shopId);
        $water = Model('Water');
        $res = $water->monthshopInday($shopId,$year,$month);
        if($res || $res==[]){
            return json(returnAjax($res));
        }else{
            return json(returnAjax('','查询数据失败','-1'));
        }
    }
}


